// pages/song-list/index.js

import { rankStore,ranks, musicStore } from "../../store/index";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    idx:0,
    rankInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {idx} = options
    this.setData({idx})
    rankStore.onState(ranks[idx],(value) => {
      if(Object.keys(value).length === 0) return
      const rankInfo = value
      this.setData({rankInfo})
      wx.setNavigationBarTitle({
        title:value.name
      })
    })
  },
  playAllMusic(){
    const musicList = this.data.rankInfo.tracks.map((item) => {
      return item.id
    })
    wx.navigateTo({
      url: `/pages/music-detail/index?id=${musicList[0]}`
    })
    musicStore.dispatch('playAllMusicAction',musicList)
  }
})